﻿using System;
using System.Linq;

namespace NoORM.Core.Contract
{
    /// <summary>
    /// 查询表达式
    /// </summary>
    public class QueryExpression
    {
        /// <summary>
        /// 表达式的连接词AND或OR
        /// </summary>
        public string Prefix { get; set; }

        /// <summary>
        /// 左边的括号
        /// </summary>
        public string LeftBrackets { get; set; }

        /// <summary>
        /// 字段名称
        /// </summary>
        public string Field { get; set; }

        private string _operator;
        /// <summary>
        /// 操作符
        /// </summary>
        public string Operator
        {
            get
            {
                return string.IsNullOrEmpty(this._operator) ? "=" : this._operator;
            }
            set
            {
                string[] array = new[] { "<", "<=","=",">=",">","<>","like","in","not in" };
                if (!array.Contains(value))
                {
                    throw new Exception($"不可识别的操作符{value}");
                }
                else
                {
                    this._operator = value;
                }
            }
        }

        /// <summary>
        /// 比较的值
        /// </summary>
        public dynamic Value { get; set; }

        /// <summary>
        /// 右边的括号
        /// </summary>
        public string RightBrackets { get; set; }
    }
}
